---
layout: m1x_soap
title: Catalog Category
---


<h2><a name="MAPI-Category-Module%3AMageCatalog"></a>Module: Mage_Catalog</h2>

<p>The Mage_Catalog module allows you to manage categories and products.</p>

<h4><a name="MAPI-Category-Category"></a>Category</h4>

<p>Allows you to manage categories and how products are assigned to categories.</p>

<p><b>Resource Name</b>: catalog_category</p>

<p><b>Aliases</b>:</p>
<ul>
	<li>category</li>
</ul>


<p><b>Methods</b>:</p>
<ul>
	<li><a href="catalog_category.currentStore.html" title="catalog_category.currentStore">catalog_category.currentStore</a> &#45; Set/Get the current store view</li>
	<li><a href="catalog_category.tree.html" title="catalog_category.tree">catalog_category.tree</a> &#45; Retrieve the hierarchical category tree</li>
	<li><a href="catalog_category.level.html" title="catalog_category.level">catalog_category.level</a> &#45; Retrieve one level of categories by a website, store view, or parent category</li>
	<li><a href="catalog_category.info.html" title="catalog_category.info">catalog_category.info</a> &#45; Retrieve the category data</li>
	<li><a href="catalog_category.create.html" title="catalog_category.create">catalog_category.create</a> &#45; Create a new category</li>
	<li><a href="catalog_category.update.html" title="catalog_category.update">catalog_category.update</a> &#45; Update a category</li>
	<li><a href="catalog_category.move.html" title="catalog_category.move">catalog_category.move</a> &#45; Move a category in its tree</li>
	<li><a href="catalog_category.delete.html" title="catalog_category.delete">catalog_category.delete</a> &#45; Delete a category</li>
	<li><a href="catalog_category.assignedProducts.html" title="catalog_category.assignedProducts">catalog_category.assignedProducts</a> &#45; Retrieve a list of products assigned to a category</li>
	<li><a href="catalog_category.assignProduct.html" title="catalog_category.assignProduct">catalog_category.assignProduct</a> &#45; Assign product to a category</li>
	<li><a href="catalog_category.updateProduct.html" title="catalog_category.updateProduct">catalog_category.updateProduct</a> &#45; Update an assigned product</li>
	<li><a href="catalog_category.removeProduct.html" title="catalog_category.removeProduct">catalog_category.removeProduct</a> &#45; Remove a product assignment</li>
</ul>


<h4><a name="MAPI-Category-Faults"></a>Faults</h4>


<table><tbody>
<tr>
<th> Fault Code </th>
<th> Fault Message </th>
</tr>
<tr>
<td> 100 </td>
<td> Requested store view not found. </td>
</tr>
<tr>
<td> 101 </td>
<td> Requested website not found. </td>
</tr>
<tr>
<td> 102 </td>
<td> Category not exists. </td>
</tr>
<tr>
<td> 103 </td>
<td> Invalid data given. Details in error message. </td>
</tr>
<tr>
<td> 104 </td>
<td> Category not moved. Details in error message. </td>
</tr>
<tr>
<td> 105 </td>
<td> Category not deleted. Details in error message. </td>
</tr>
<tr>
<td> 106 </td>
<td> Requested product is not assigned to category. </td>
</tr>
</tbody></table>


<h4><a name="MAPI-Category-Example1.Workingwithcategories"></a>Example 1. Working with categories</h4>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<div id="root">
		<pre class="theme: Default; brush: java; gutter: false">function getSomeRandomCategory(&amp;$categories, $targetLevel, $currentLevel = 0) {
    if (count($categories)==0) {
        return false;
    }
    if ($targetLevel == $currentLevel) {
        return $categories[array_rand($categories)];
    } else {
        return getSomeRandomCategory($categories[array_rand($categories)]['children'], $targetLevel + 1);
    }
}

$proxy = new SoapClient('http://magentohost/api/soap/?wsdl');
$sessionId = $proxy-&gt;login('apiUser', 'apiKey');
$allCategories = $proxy-&gt;call($sessionId, 'category.tree'); // Get all categories.

// select random category from tree
while (($selectedCategory = getSomeRandomCategory($allCategories, 3)) === false) {}

// create new category
$newCategoryId = $proxy-&gt;call(
    $sessionId,
    'category.create',
    array(
        $selectedCategory['category_id'],
         array(
                'name'=&gt;'Newopenerp',
                'is_active'=&gt;1,
                'include_in_menu'=&gt;2,
                'available_sort_by'=&gt;'position',
                'default_sort_by'=&gt;'position'
               )
    )
);

$newData = array('is_active'=&gt;1);
// update created category on German store view
$proxy-&gt;call($sessionId, 'category.update', array($newCategoryId, $newData, 'german'));

$firstLevel = $proxy-&gt;call($sessionId, 'category.level', array(null, 'german', $selectedCategory['category_id']));

var_dump($firstLevel);

// If you wish remove category, uncomment next line
//$proxy-&gt;call($sessionId, 'category.delete', $newCategoryId);</pre>
		</div>
</div></div>

<h4><a name="MAPI-Category-Example2.Workingwithassignedproducts"></a>Example 2. Working with assigned products</h4>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<div id="root">
		<pre class="theme: Default; brush: java; gutter: false">$proxy = new SoapClient('http://magentohost/api/soap/?wsdl');
$sessionId = $proxy-&gt;login('apiUser', 'apiKey');

$categoryId = 5; // Put here your category id
$storeId = 1; // You can add store level

$assignedProducts = $proxy-&gt;call($sessionId, 'category.assignedProducts', array($categoryId, $storeId));
var_dump($assignedProducts); // Will output assigned products.

// Assign product
$proxy-&gt;call($sessionId, 'category.assignProduct', array($categoryId, 'someProductSku', 5));

// Update product assignment postion
$proxy-&gt;call($sessionId, 'category.updateProduct', array($categoryId, 'someProductSku', 25));

// Remove product assignment
$proxy-&gt;call($sessionId, 'category.removeProduct', array($categoryId, 'someProductSku'));</pre>
		</div>
</div></div>
<?php include(__ROOT__ . 'footer.php'); ?>